package com.weaver.drools.common.entity;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;

import com.weaver.drools.common.utils.MyDES;
/**
 * 
 *  @application name:
 *  @author: zhouxinlei 
 *  @time：2018年6月27日
 *  @version：ver 1.1
 */
@Entity
@Table(name = "SYS_USER")
public class SysUser implements java.io.Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(generator = "snowFlakeId")
	@GenericGenerator(name = "snowFlakeId", strategy = "com.weaver.drools.common.businesskey.SnowFlakeId")
	@Column(name = "USER_ID",nullable = false,length = 20)
	private Long id;
	@Column(name = "USER_NAME", nullable = false, length = 20)
	private String username;
	@Column(name = "PASSWORD", nullable = false)
	private String password;
	@Column(name = "DISPLAY_NAME", nullable = false, length = 20)
	private String displayName;
	@Column(name = "SEX", nullable = false, length = 1)
	private Long sex;
	@Column(name = "BIRTH_DAY", nullable = false)
	private Date birthDay;
	@Column(name = "TEL_PHONE", nullable = true, length = 11)
	private String telPhone;
	@Column(name = "EMAIL", nullable = true, length = 20)
	private String email;
	@Column(name = "WECHAT", nullable = true, length = 20)
	private String weChat;
	@Column(name = "ISDEL", nullable = false, length = 1)
	private Long isdel;
	@Column(name = "CD_TIME", nullable = false)
    private Date cdTime;
	@Column(name = "UP_TIME", nullable = false)
	private Date upTime;
	@Column(name = "STATE", nullable = true, length = 1)
    private Long state;//用户状态,0:创建未认证（比如没有激活，没有输入验证码等等）--等待验证的用户 , 1:正常状态,2：用户被锁定
	@Column(name = "LAST_LOGIN_TIME", nullable = false)
	private Date lastLoginTime;
	
	@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinTable(name = "USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID") }, 
    inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID") })
	@OrderBy("ROLE_ID asc")
	private Set<SysRole> roles= new HashSet<SysRole>();
	
	public SysUser() {
		super();
	}

	public Long getSex() {
		return sex;
	}


	public void setSex(Long sex) {
		this.sex = sex;
	}


	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public Long getId() {
		return id;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public Date getBirthDay() {
		return birthDay;
	}

	public String getTelPhone() {
		return telPhone;
	}

	public String getEmail() {
		return email;
	}

	public String getWeChat() {
		return weChat;
	}

	public Long getIsdel() {
		return isdel;
	}

	public Date getCdTime() {
		return cdTime;
	}

	public Date getUpTime() {
		return upTime;
	}

	public Long getState() {
		return state;
	}

	public Set<SysRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<SysRole> roles) {
		this.roles = roles;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = MyDES.encryptBasedDes(password+username);
	}

	public void setBirthDay(Date birthDay) {
		this.birthDay = birthDay;
	}

	public void setTelPhone(String telPhone) {
		this.telPhone = telPhone;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setWeChat(String weChat) {
		this.weChat = weChat;
	}

	public void setIsdel(Long isdel) {
		this.isdel = isdel;
	}

	public void setCdTime(Date cdTime) {
		this.cdTime = cdTime;
	}

	public void setUpTime(Date upTime) {
		this.upTime = upTime;
	}

	public void setState(Long state) {
		this.state = state;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}
    
}